﻿package net.wangit.util;

import java.io.UnsupportedEncodingException;

/**
 * 字符编码转换
 * 
 * @author watson Feb 26, 2010
 */
public class CodeUtil {

	private CodeUtil() {
	}

	public static String GB23122ISO(String strIn) {
		String strOut = null;
		if (strIn == null || strIn.trim().equals(""))
			return strIn;
		try {
			byte[] b = strIn.getBytes("gb2312");
			strOut = new String(b, "ISO8859_1");
		} catch (UnsupportedEncodingException e) {
			return null;
		}
		return strOut;
	}

	public static String GBK2ISO(String strIn) {
		String strOut = null;
		if (Checker.isEmpty(strIn))
			return strIn;
		try {
			byte[] b = strIn.getBytes("GBK");
			strOut = new String(b, "ISO8859_1");
		} catch (UnsupportedEncodingException e) {
			return "";
		}
		return strOut;
	}

	public static String ISO2GB2312(String strIn) {
		String strOut = null;
		if (Checker.isEmpty(strIn))
			return strIn;
		try {
			byte[] b = strIn.getBytes("ISO8859_1");
			strOut = new String(b, "gb2312");
		} catch (UnsupportedEncodingException e) {
			return "";
		}
		return strOut;
	}

	public static String ISO2GBK(String strIn) {
		String strOut = null;
		if (Checker.isEmpty(strIn))
			return strIn;
		try {
			byte[] b = strIn.getBytes("ISO8859_1");
			strOut = new String(b, "GBK");
		} catch (UnsupportedEncodingException e) {
			return "";
		}
		return strOut;
	}
}
